package ylzy.com.yanglezhiyang;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    GameView gameView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gameView = findViewById(R.id.gameView);
        gameView.postDelayed(runnable, 500);
    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            SoundPoolUtils.playLoopBG(SoundPoolUtils.SOUND_BG);
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        getWindow().setAttributes(params);
        if (Build.VERSION.SDK_INT >= 19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }

        SoundPoolUtils.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        SoundPoolUtils.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SoundPoolUtils.onDestroy();
        gameView.removeCallbacks(runnable);
    }
}
